package api

import (
	"blogdemo/gin/errmsg"
	"blogdemo/gin/model"
	"fmt"
	"github.com/gin-gonic/gin"
	"net/http"
)

func ShowArticleRecord(c *gin.Context) {
	username := c.Param("username")
	var article []model.Article
	var flag bool
	article, flag = model.GetArticle(username)
	if !flag {
		c.JSON(http.StatusBadRequest, gin.H{
			"status": errmsg.ARTICLE_NO,
			"data":   article,
			"msg":    errmsg.GetErrMsg(errmsg.ARTICLE_NO),
		})
		fmt.Println("该用户暂未发表文章")
		c.Abort()
		return
	}
	c.JSON(http.StatusOK, gin.H{
		"status": errmsg.SUCCESS,
		"data":   article,
		"msg":    errmsg.GetErrMsg(errmsg.SUCCESS),
	})
	fmt.Println("成功获取用户发表文章")
}
